package com.pd.dong.generate.plugins;

import com.pd.dong.generate.vtl.GeneratorInfo;
import com.pd.dong.generate.vtl.VelocityUtils;
import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.config.TableConfiguration;

import java.util.ArrayList;
import java.util.List;

public class GenServicePlugin extends BasePlugin {

    @Override
    public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {

        String targetProject = this.getContext().getJavaModelGeneratorConfiguration().getTargetProject();
        String targetPackage = this.getContext().getJavaModelGeneratorConfiguration().getTargetPackage();

        this.getContext().getTableConfigurations().forEach(table -> {
            GeneratorInfo generatorInfo = new GeneratorInfo();
            generatorInfo.setDomainObjectName(table.getDomainObjectName());
            generatorInfo.setPackagePath(targetPackage);
            generatorInfo.setProjectPath(targetProject);

            VelocityUtils.generateCode(generatorInfo);
        });

        return new ArrayList<>();
    }
}
